﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;

namespace myomscl_web.Utils
{
    public static class Extensions
    {
        /// <summary>
        /// Searches recursively in this control to find a control with the name specified.
        /// </summary>        
        public static Control FindControlRecursive(this Control root, string id)
        {
            System.Web.UI.Control controlFound;
            if (root != null)
            {
                controlFound = root.FindControl(id);
                if (controlFound != null)
                {
                    return controlFound;
                }
                foreach (Control c in root.Controls)
                {
                    controlFound = c.FindControlRecursive(id);
                    if (controlFound != null)
                    {
                        return controlFound;
                    }
                }
            }
            return null;
        }
    }
}